package com.idefav.Controllers;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by wzs on 2017/7/22.
 */
@RestController
@RequestMapping("/hello")
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "helloFallback")
    @RequestMapping(value = "/say/{test}", method = RequestMethod.GET)
    public String hello(@PathVariable("test") String test) {
        return restTemplate.getForEntity("http://HELLO-SERVICE/hello/say/{1}", String.class, test).getBody();
    }
    @HystrixCommand(fallbackMethod = "helloFallback")
    @RequestMapping(value = "/test/{test}", method = RequestMethod.GET)
    public String test(@PathVariable("test") String test){
        return restTemplate.getForEntity("http://HELLO-SERVICE/hello/say/{1}", String.class, test).getBody();
    }

    private String helloFallback(String test){
        return "default test";
    }
}
